
package com.contractmodule.dao;
import com.contractmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbProjectStateDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbProjectState tbProjectState=null;
    private List<TbProjectState> tbProjectStateList=null;

    public boolean add(TbProjectState inTbProjectState){
        try{
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_ProjectState(IsFinish,InitialTest,CompletionData,IsPaperReview,IsElectronicProcesses,FlowProcessId,IsInvoice,InvoiceTime,IsBackSection,UserId) values(?,?,?,?,?,?,?,?,?,?)";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbProjectState.getIsFinish());
        pt.setInt(2,inTbProjectState.getInitialTest());
        pt.setString(3,inTbProjectState.getCompletionData());
        pt.setInt(4,inTbProjectState.getIsPaperReview());
        pt.setInt(5,inTbProjectState.getIsElectronicProcesses());
        pt.setInt(6,inTbProjectState.getFlowProcessId());
        pt.setInt(7,inTbProjectState.getIsInvoice());
        pt.setString(8,inTbProjectState.getInvoiceTime());
        pt.setInt(9,inTbProjectState.getIsBackSection());
        pt.setInt(10,inTbProjectState.getUserId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inProjectStateId){
        return UtilDAO.del("Tb_ProjectState", "ProjectStateId", inProjectStateId);
    }
    public boolean edit(TbProjectState inTbProjectState){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_ProjectState set IsFinish=?,InitialTest=?,CompletionData=?,IsPaperReview=?,IsElectronicProcesses=?,FlowProcessId=?,IsInvoice=?,InvoiceTime=?,IsBackSection=?,UserId=?,CreateTime=getdate() where ProjectStateId=?";
        pt = conn.prepareStatement(sql);
        pt.setInt(1,inTbProjectState.getIsFinish());
        pt.setInt(2,inTbProjectState.getInitialTest());
        pt.setString(3,inTbProjectState.getCompletionData());
        pt.setInt(4,inTbProjectState.getIsPaperReview());
        pt.setInt(5,inTbProjectState.getIsElectronicProcesses());
        pt.setInt(6,inTbProjectState.getFlowProcessId());
        pt.setInt(7,inTbProjectState.getIsInvoice());
        pt.setString(8,inTbProjectState.getInvoiceTime());
        pt.setInt(9,inTbProjectState.getIsBackSection());
        pt.setInt(10,inTbProjectState.getUserId());
        pt.setInt(11,inTbProjectState.getProjectStateId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbProjectState getTbProjectStateByProjectStateId(int inProjectStateId) {
        tbProjectState=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_ProjectState where ProjectStateId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inProjectStateId);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbProjectState = getTbProjectState(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbProjectState;
    }
    public List<TbProjectState> getTbProjectStateAll() {
        tbProjectStateList=new ArrayList<TbProjectState>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_ProjectState";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbProjectStateList.add(getTbProjectState(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbProjectStateList;
    }
    /**
     * get the ProjectStates by projectStateIds
     *@author qingyu zhang
     *@function:
     * @param projectStateId
     * @return
     *2011-6-19
     *上午11:09:03
     *ProjectManagerT
     *com.contractmodule.dao
     *List<TbProjectState>
     */
    public List<TbProjectState> getTbProjectStateAll(String projectStateId) {
    	tbProjectStateList=new ArrayList<TbProjectState>();
    	try{
    		conn = ConnectDB.getSqlServerConnection();
    		sql = "select * from Tb_ProjectState where ProjectStateId in ("+projectStateId+")";
    		pt = conn.prepareStatement(sql);
    		rs = pt.executeQuery();
    		while (rs.next()) {
    			tbProjectStateList.add(getTbProjectState(rs));
    		}
    	}catch(Exception e){
    		e.printStackTrace();
    	}finally {
    		ConnectDB.closeSqlConnection();        }
    	return tbProjectStateList;
    }
    public List<TbProjectState> getTbProjectStateAll(VskPage vp) {
        tbProjectStateList=new ArrayList<TbProjectState>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_ProjectState";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_ProjectState", "ProjectStateId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbProjectStateList.add(getTbProjectState(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbProjectStateList;
    }
    public TbProjectState getTbProjectState(ResultSet rs) throws Exception{
        TbProjectState tbProjectState = new TbProjectState();
        tbProjectState.setProjectStateId(rs.getInt("ProjectStateId"));
        tbProjectState.setIsFinish(rs.getInt("IsFinish"));
        tbProjectState.setInitialTest(rs.getInt("InitialTest"));
        tbProjectState.setCompletionData(rs.getString("CompletionData"));
        tbProjectState.setIsPaperReview(rs.getInt("IsPaperReview"));
        tbProjectState.setIsElectronicProcesses(rs.getInt("IsElectronicProcesses"));
        tbProjectState.setFlowProcessId(rs.getInt("FlowProcessId"));
        tbProjectState.setIsInvoice(rs.getInt("IsInvoice"));
        tbProjectState.setInvoiceTime(rs.getString("InvoiceTime"));
        tbProjectState.setIsBackSection(rs.getInt("IsBackSection"));
        tbProjectState.setUserId(rs.getInt("UserId"));
        tbProjectState.setCreateTime(rs.getString("CreateTime"));
        return tbProjectState;
    }
}
